|
|
|
| Add a Class_Initialize() Event 1. Add the following code to the Class_Initialize event: | | Private Sub Class_Initialize()
mlngEmpID = 1
mcurSalary = 25000
End Sub |  | Now when you create an instance of this class, the mlngEmpID variable will be initialized to 1 and the mcurSalary variable will be initialized to 25000. To test this, lets use the form created by Visual Basic when you first entered the Visual Basic design environment. Follow the steps in the next exercise to create a form that uses the Employee class. |
|
|
| Using Your New Class Module 1. Add a command button to the default form that was created when you entered the new project. 2. Set the Name property to cmdDisplay. 3. Set the Caption property to Display. 4. Double-click this command button. 5. Add the following code to this command button: | | Private Sub cmdDisplay_Click()
Dim oEmp As Employee
Set oEmp = New Employee
MsgBox oEmp.Salary
End Sub |  | When you click the command button at runtime, the Class_Initialize() event will be fired just prior to the call to the Property Get procedure for Salary(). This means the mcurSalary variable will be initialized to the value 25000. When you use the Salary property attached to the Employee object, the Property Get routine will be fired. The value in the mcurSalary variable is returned and passed to the MsgBox statement to be displayed on the screen. |
|
|
|